package com.ruoyi.common.core.page;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import java.util.List;

public class PageUtil {

    /**
     * 开始分页查询
     *
     * @param pageQuery
     */
    public static void startPage(PageQuery pageQuery) {
        PageHelper.startPage(pageQuery.getPageNo(), pageQuery.getPageSize());
    }

    /**
     * 获取分页信息
     * @param dataList
     * @param <T>
     * @return
     */
    public static <T> PageList<T> getPageList(List<T> dataList) {
        PageInfo<T> pageInfo = new PageInfo<>(dataList);
        PageList<T> pageList = new PageList<>();
        pageList.setPageNo(pageInfo.getPageNum());
        pageList.setPageSize(pageInfo.getPageSize());
        pageList.setPageTotal(pageInfo.getPages());
        pageList.setTotal(pageInfo.getTotal());
        pageList.setData(dataList);
        return pageList;
    }
}
